<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>订单管理</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/zTree/css/zTreeStyle/zTreeStyle.css"/>
</head>

<body>
<% include("../layout/loading.html"){} %>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <form>
                    <div class="layui-inline" >
                        <label class="layui-form-label">兑换时间:</label>
                        <div class="layui-input-inline" style="width: 230px">
                            <input type="text" class="layui-input date-icon" id="searchDate" placeholder="请选择时间" name="searchDate" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">所属机构:</label>
                        <div class="layui-input-block" style="width: 230px">
                            <select name="organizationId">
                                <option value="">全部</option>
                                <% for(organization in organizationList) { %>
                                <option value="${organization.id}">${organization.organizationName}</option>
                                <% } %>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">取货门店:</label>
                        <div class="layui-input-block" style="width: 230px">
                            <select name="schoolId">
                                <option value="">全部</option>
                                <% for(school in schoolList) { %>
                                <option value="${school.id}">${school.schoolName}</option>
                                <% } %>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键词:</label>
                            <div class="layui-input-block" style="width: 230px">
                                <input type="text" name="keyWords" autocomplete="off" placeholder="搜索礼品名称/学员姓名/手机号"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单状态</label>
                            <div class="layui-input-inline" style="width: 230px">
                                <select name="status" id="status">
                                    <option value="">全部</option>
                                    <option value="0">未取</option>
                                    <option value="1">已取</option>
                                </select>
                            </div>
                        </div>


                        <div class="layui-inline">
                            <button lay-submit="" lay-filter="btnSearchSubmit" type="submit" class="layui-btn icon-btn">
                                <i class="layui-icon">&#xe615;</i>查询
                            </button>
                            <!--                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>查询</button>-->
                            <button id="btnReset" class="layui-btn icon-btn"><i class="layui-icon">&#xe669;</i>重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>

            <table class="layui-table" id="orderTable" lay-filter="orderTable"></table>
        </div>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="tableBar">
<!--    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="details">查看</a>-->
<!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
    {{# if(d.status==1){ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs " id="update-class-{{d.id}}" style="display:none;" lay-event="updateStatus">完成取货</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs " id="update-class-{{d.id}}" lay-event="updateStatus">完成取货</a>
    {{# } }}
</script>
<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/libs/jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/libs/zTree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/js/common.js"></script>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laydate = layui.laydate;
        var util = layui.util;
        var admin = layui.admin;
        laydate.render({elem: '#searchDate', range: true,value: '',isInitValue:true});

        // 渲染表格
        var insTb = table.render({
            elem: '#orderTable',
            url: '/admin/order/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {field: 'orderNo', title: '订单号'},
                {field: 'childName', title: '学员姓名'},
                {field: 'telNo', title: '手机号'},
                {field: 'productName', title: '礼品'},
                {field: 'price', title: '所用豆藤'},
                {field: 'organizationName', title: '所属机构'},
                {field: 'schoolName', title: '取货门店'},
                {field: 'createdDate', title: '下单时间'},
                {field: 'statusName', title: '订单状态'},
                {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
            ]]
        });

        //监听提交搜索
        form.on('submit(btnSearchSubmit)', function (data) {
            var res = data.field;
            // console.log(res)
            insTb.reload({where: res, page: 1});
            return false;
        });

        // 重置
        $('#btnReset').click(function () {
            $('#edtSearch').val("");
            window.location.reload();
        });

        // 工具条点击事件
        table.on('tool(orderTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'updateStatus') { // 完成取货
                updateStatus(obj);
            }
        });

        // 完成取货
        function updateStatus(obj) {
            top.layer.confirm('“该订单' + obj.data.orderNo + '”要确认收货吗？', {
                skin: 'layui-layer-admin'
            }, function (i) {
                top.layer.close(i);
                layer.load(2);
                $.post('/admin/order/updateStatus', {
                    orderId: obj.data.id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        window.location.reload();
                        // obj.del();
                    } else {
                        layer.msg(res.msg);
                    }
                }, 'json');
            });
        }
    });
</script>
</body>
</html>